<template>
    <div>
        <mt-field label="学号" placeholder="请输入用户名" v-model="userSid"></mt-field>
        <mt-field label="密码" placeholder="请输入密码" type="password" v-model="userPassword"></mt-field>

        <mt-button type="default" @click="login">登录</mt-button>
        <router-link to="/app/register">注册</router-link>
    </div>
</template>

<script>
    import {login} from "../../../api";
    import { Toast } from 'mint-ui';

    export default {
        name: "Login",
        data(){
            return {
                userSid: "",
                userPassword: ""
            }
        },
        methods:{
            async login(){
                let data = {
                    userSid: this.userSid,
                    userPassword: this.userPassword
                }
                let result = await login(data)
                if (result.status == 0 ){
                    let user = result.data
                    user['isLogin'] = true
                    this.$store.dispatch('setUser',user)
                    this.$router.push({
                        path: '/app/my'
                    })
                }else {
                    Toast({
                        message: result.msg,
                        duration: 5000
                    })
                }
            }
        }
    }
</script>

<style scoped>

</style>